﻿using AutoMapper;
using Resume.Model;
using Resume.ViewModels;

namespace Resume.Common
{
    public class AutoMapperConfigs : Profile
    {
        /// <summary>
        /// 可以配置互转的类，数据实体转视图实体
        /// </summary>
        public AutoMapperConfigs()
        {
            CreateMap<FieldClassDict, FieldClassDictViewModel>()
                .ForMember(dest => dest.ObjID, option => option.MapFrom(op => op.Id))
                .ForMember(dest => dest.Remark, option => option.MapFrom(op => op.FieldClassRemark))
                .ForMember(dest => dest.ObjName, option => option.MapFrom(op => op.FieldClassName))
                .ForMember(dest => dest.Enable, option => option.MapFrom(op => op.Status == 1 ? true : false));

            CreateMap<Page<FieldClassDict>, Page<FieldClassDictViewModel>>();

            CreateMap<FieldSettingDict, FieldSettingViewModel>()
                .ForMember(dest => dest.ObjID, option => option.MapFrom(op => op.Id))
                .ForMember(dest => dest.ObjPID, option => option.MapFrom(op => op.FieldClassCode))
                .ForMember(dest => dest.Remark, option => option.MapFrom(op => op.FieldRemark))
                .ForMember(dest => dest.ObjName, option => option.MapFrom(op => op.FieldName))
                .ForMember(dest => dest.Enable, option => option.MapFrom(op => op.Status == 1 ? true : false));

            CreateMap<Page<FieldSettingDict>, Page<FieldSettingViewModel>>();

            CreateMap<UsersDict, UsersDictViewModel>()
                .ForMember(dest => dest.ID, option => option.MapFrom(op => op.Id))
                .ForMember(dest => dest.name, option => option.MapFrom(op => op.UserName))
                .ForMember(dest => dest.sex, option => option.MapFrom(op => op.Sex))
                .ForMember(dest => dest.birthday, option => option.MapFrom(op => op.BirthDay))
                .ForMember(dest => dest.phone, option => option.MapFrom(op => op.PhoneNumber))
                .ForMember(dest => dest.email, option => option.MapFrom(op => op.Email))
                .ForMember(dest => dest.nation, option => option.MapFrom(op => op.Nation))
                .ForMember(dest => dest.politicaloutlook, option => option.MapFrom(op => op.PoliticalOutlook))
                .ForMember(dest => dest.jobintention, option => option.MapFrom(op => op.JobIntention))
                .ForMember(dest => dest.enable, option => option.MapFrom(op => op.Status == 1 ? true : false));

            CreateMap<Page<UsersDict>, Page<UsersDictViewModel>>();
        }
    }
}